<?php 
require_once "class.db.php";
class theloai extends db{
	
	/* QUAN LY CHUNG LOAI */
	function TheLoai_Them(&$loi){	
	
		$thanhcong=true;
		$Logo = $this->processData($_POST[UrlHinh]);
		$TenGiai = $this->processData($_POST[TenGiai]);
		$TenGiai_KD = $this->processData($_POST[TenGiai_KD]);
		$Nam = $this->processData($_POST[Nam]);
		
		if($TenGiai=="")
		{
			$thanhcong= false;
			$loi[$TenGiai]= "Chưa nhập tên giải đấu";
		}
	
		if($thanhcong==false){
			return $thanhcong;
		}else{
			$sql = "INSERT INTO giaidau 
					VALUES(NULL,'$TenGiai','$TenGiai_KD','$Logo','$Nam')";
			mysql_query($sql) or die(mysql_error().$sql);		
		}
		return $thanhcong;
	}
	function TheLoai_Edit($idGiai,&$loi){
		settype($idTL,"int");
		$thanhcong=true;
		$Logo = $this->processData($_POST[UrlHinh]);
		$TenGiai = $this->processData($_POST[TenGiai]);
		$TenGiai_KD = $this->processData($_POST[TenGiai_KD]);
		$Title = $this->processData($_POST[Title]);
		$MetaD = $this->processData($_POST[MetaD]);
		$MetaK = $this->processData($_POST[MetaK]);		
		
		if($TenGiai_KD=="") $TenGiai_KD = $this->changeTitle($TenGiai);
		
		if($TenGiai=="")
		{
			$thanhcong= false;
			$loi[TenGiai]= "Chưa nhập tên chủng loại";
		}
	
		if($thanhcong==false){
			return $thanhcong;
		}else{
			$sql = "UPDATE giaidau 
					SET TenGiai = '$TenGiai',TenGiai_KD = '$TenGiai_KD',Logo = '$Logo'					 
					WHERE IDGiai = $idGiai";
			mysql_query($sql) or die(mysql_error().$sql);		
		}
		return $thanhcong;
	}
	function TheLoai_List($limit=-1,$offset=-1){
		$sql = "SELECT * FROM theloai  ";
		if($limit >0 && $offset >=0) $sql.= " LIMIT $offset,$limit";
		$rs = mysql_query($sql) or die(mysql_error());
		return $rs;
	}
	function TheLoai_ChiTiet($idGiai){
		$sql = "SELECT * FROM giaidau WHERE IDGiai = $idGiai";
		$rs = mysql_query($sql) or die(mysql_error());
		return $rs;
	}
	function getIdTL($TenTL_KD){
		$sql = "SELECT idTL FROM theloai WHERE TenTL_KD = '$TenTL_KD'";
		$rs = mysql_query($sql) or die(mysql_error());
		$row = mysql_fetch_assoc($rs);
		$idTL = $row[idTL];
		return $idTL;
	}
}

?>